import logging
from smtplib import SMTPRecipientsRefused

from django.core.mail import send_mail

from NewStudentManageSys.settings import dev

logger = logging.getLogger('django')

def send_emails(template, user_name, user_email, server_name, server_wechat, server_email, html_message):
    """发送邮件"""
    send_dict = {
        'subject': template['title'] % user_name,
        'message': template['content'] % (user_name, server_name, server_name, server_wechat, server_email),
        'from_email': dev.EMAIL_FROM,
        'recipient_list': [user_email, ],
        'html_message': html_message
    }
    try:
        send_mail(**send_dict)
    except SMTPRecipientsRefused as e:
        logger.info(e)
        return
